C++ 引用 发表于 2015-04-17 | 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#include <iostream>using namespace std;typedef struct { int x; int y;}Coord;void func(int &a, int &b);int main(int argc, const char * argv[]) { // 引用:必须要初始化// int a = 3;// 类型 *&指针引用名 = 指针;// int a = 10;// int *p = &a;// int *&q = p;// *q = 20;// cout << a << endl; int a = 10; int &b = a; b = 20; cout << a << endl; cout << b << endl; Coord c; Coord &c1 = c; c1.x = 20; c1.y = 30; cout << c.x << ' ' << c.y << endl; int a1 = 10; int a2 = 40; cout << a1 << ' ' << a2 << endl; func(a1, a2); cout << a1 << ' ' << a2 << endl; return 0;}void func(int &a, int &b) { int c = 0; c = a; a = b; b = c;} http://blog.csdn.net/Simba888888/article/category/1464971/4